#!/usr/bin/env python
# encoding: utf-8
'''
@author: liuchong
@contact: lucas@007vin.com
@software: garner
@file: banzhou.py
@time: 2020/8/24 2:44 下午
@desc:
'''

import sys
sys.path.append('../../')
import pandas as pd
import re
from pymongo import MongoClient
import ujson
from models.audi.audi_193 import CarsPartNumNew, Vb, CarsSaDesc, CarsStructureCollectionNew
from scripts.fenci import remove_tt
from cars_scripts.service.AudiService import cleanTransmission, cleanDrive, cleanCylinder, cleanPower
from cars_scripts.service.add_date import audi_do_filter_extra_info, mergeDate

s = ['3缸', '三缸', '4缸', '四缸', '5缸', '五缸', '6缸', '六缸', '8缸', '八缸', '10缸', '十缸', '12缸', '十二缸']
qd = ['全轮驱动', '前驱动', '前部驱动', '四轮驱动']
fuel = ['汽油', '柴油']
bsx = ['7档', '7档自动', '7档手动', '7档双离合', '七档', '七档自动', '七档手动', '七档双离合', '6档', '6档自动', '6档手动', '6挡手自一体',
       '六档', '六档自动', '六档手动', '5档', '5档自动', '5档手动', '五档', '五档自动', '五档手动', '5挡手自一体',
       '4档', '4档自动', '4档手动', '四档', '四档自动', '四档手动', '8档', '8档自动', '8档手动', '8挡手自一体',
       '八档', '八档自动', '八档手动', '3档', '3档自动', '3档手动', '三档', '三档自动', '三档手动', '无级自动']
pl = ['1.4', '1.8', '2.0', '2.23', '1.9', '3.0', '1.6', '2.5', '2.8', '2.2', '2.3', '5.2', '2.4', '2.1', '3.2', '1.3', '1.1', '2.7', '4.0', '3.6', '4.2', '6.0', '2.6', '1.2', '1.5', '6.3', '1.7', '0.8', '3.7', '1.0', '3.3', '2.9', '0.9', '5.0']
fdjdm = ['AAD', 'AAE', 'AAH', 'AAN', 'AAR', 'AAS', 'AAT', 'AAZ', 'ABB', 'ABC', 'ABH', 'ABK', 'ABM', 'ABP', 'ABT', 'ABY', 'ABZ', 'ACE', 'ACK', 'ACZ', 'ADA', 'ADP', 'ADR', 'ADU', 'ADW', 'AEB', 'AEC', 'AEH', 'AEJ', 'AEL', 'AEM', 'AEW', 'AFB', 'AFC', 'AFF', 'AFM', 'AFN', 'AFY', 'AGA', 'AGB', 'AGE', 'AGH', 'AGN', 'AGR', 'AGU', 'AHA', 'AHC', 'AHF', 'AHH', 'AHK', 'AHL', 'AHU', 'AJG', 'AJK', 'AJL', 'AJM', 'AJP', 'AJQ', 'AKB', 'AKC', 'AKE', 'AKF', 'AKG', 'AKH', 'AKJ', 'AKL', 'AKN', 'ALF', 'ALG', 'ALH', 'ALT', 'ALW', 'ALZ', 'AMB', 'AMF', 'AMK', 'AML', 'AMM', 'AMU', 'AMX', 'ANA', 'ANB', 'ANK', 'ANQ', 'ANY', 'ANZ', 'APB', 'APC', 'APF', 'APG', 'APP', 'APR', 'APS', 'APT', 'APU', 'APX', 'APY', 'APZ', 'AQA', 'AQD', 'AQE', 'AQF', 'AQG', 'AQH', 'AQJ', 'ARE', 'ARG', 'ARH', 'ARJ', 'ARK', 'ARM', 'ARN', 'ARS', 'ART', 'ARU', 'ARX', 'ARY', 'ARZ', 'ASB', 'ASE', 'ASG', 'ASJ', 'ASM', 'ASN', 'ASV', 'ASZ', 'ATC', 'ATD', 'ATJ', 'ATL', 'ATQ', 'ATW', 'ATX', 'AUA', 'AUK', 'AUL', 'AUM', 'AUQ', 'AUW', 'AUX', 'AVB', 'AVF', 'AVG', 'AVJ', 'AVK', 'AVP', 'AVU', 'AVV', 'AWA', 'AWL', 'AWM', 'AWN', 'AWP', 'AWT', 'AWX', 'AXR', 'AXW', 'AXX', 'AYM', 'AYS', 'AZA', 'AZB', 'AZC', 'AZR', 'AZV', 'BAD', 'BAG', 'BAH', 'BAM', 'BAR', 'BAS', 'BAT', 'BAU', 'BBD', 'BBG', 'BBJ', 'BBK', 'BBY', 'BCS', 'BCY', 'BCZ', 'BDB', 'BDG', 'BDH', 'BDV', 'BDW', 'BDX', 'BEA', 'BEL', 'BES', 'BEX', 'BFB', 'BFC', 'BFL', 'BFM', 'BFQ', 'BFV', 'BGB', 'BGK', 'BGN', 'BGU', 'BHC', 'BHE', 'BHF', 'BHK', 'BHT', 'BHZ', 'BKB', 'BKC', 'BKD', 'BKE', 'BKH', 'BKN', 'BLB', 'BLF', 'BLP', 'BLR', 'BLS', 'BLX', 'BLY', 'BMB', 'BMC', 'BMJ', 'BMK', 'BMM', 'BMN', 'BNA', 'BND', 'BNG', 'BNK', 'BNS', 'BPF', 'BPG', 'BPJ', 'BPK', 'BPP', 'BPW', 'BPY', 'BRB', 'BRC', 'BRD', 'BRE', 'BRF', 'BRV', 'BSB', 'BSE', 'BSF', 'BSG', 'BSM', 'BTE', 'BTR', 'BUB', 'BUG', 'BUH', 'BUJ', 'BUL', 'BUN', 'BUY', 'BVA', 'BVF', 'BVG', 'BVJ', 'BVN', 'BVP', 'BVR', 'BVY', 'BVZ', 'BWA', 'BWE', 'BWT', 'BXA', 'BXE', 'BYH', 'BYK', 'BYT', 'BYU', 'BZB', 'BZC', 'CABA', 'CABB', 'CABD', 'CADA', 'CAEA', 'CAEB', 'CAED', 'CAGA', 'CAGB', 'CAGC', 'CAHA', 'CAHB', 'CAJA', 'CAKA', 'CALA', 'CALB', 'CAMA', 'CAMB', 'CANA', 'CANB', 'CANC', 'CAND', 'CAPA', 'CASA', 'CASB', 'CATA', 'CAUA', 'CAVG', 'CAWB', 'CAXA', 'CAXC', 'CAYB', 'CAYC', 'CBAA', 'CBAB', 'CBBB', 'CBEA', 'CBFA', 'CBRA', 'CBZA', 'CBZB', 'CCAA', 'CCBA', 'CCDA', 'CCEA', 'CCFA', 'CCFC', 'CCGA', 'CCLA', 'CCMA', 'CCSA', 'CCTA', 'CCUA', 'CCWA', 'CCWB', 'CCZA', 'CCZC', 'CDAA', 'CDHA', 'CDHB', 'CDLA', 'CDLB', 'CDLC', 'CDLH', 'CDMA', 'CDNA', 'CDNB', 'CDNC', 'CDRA', 'CDSB', 'CDTA', 'CDTB', 'CDTC', 'CDUC', 'CDUD', 'CDYA', 'CDYB', 'CDYC', 'CDZA', 'CEJA', 'CEPA', 'CEPB', 'CESA', 'CETA', 'CEUA', 'CEUC', 'CFFA', 'CFFB', 'CFGB', 'CFGC', 'CFGD', 'CFHB', 'CFHD', 'CFKA', 'CFSA', 'CGKA', 'CGKB', 'CGLA', 'CGLB', 'CGLC', 'CGLD', 'CGLE', 'CGMA', 'CGQB', 'CGTA', 'CGWA', 'CGWB', 'CGWC', 'CGWD', 'CGXA', 'CGXB', 'CGXC', 'CHHB', 'CHHC', 'CHJA', 'CHMA', 'CHMB', 'CHPB', 'CHVA', 'CHZB', 'CHZD', 'CHZE', 'CHZJ', 'CJBA', 'CJCA', 'CJCB', 'CJCC', 'CJCD', 'CJEB', 'CJED', 'CJEE', 'CJGA', 'CJGC', 'CJMA', 'CJSA', 'CJSB', 'CJTB', 'CJTC', 'CJWB', 'CJWC', 'CJWE', 'CJXB', 'CJXC', 'CJXD', 'CJXF', 'CJXG', 'CJZA', 'CKVB', 'CKVC', 'CKVD', 'CLAA', 'CLAB', 'CLHA', 'CLJA', 'CLLB', 'CLXA', 'CLXB', 'CLZB', 'CMBA', 'CMDA', 'CMEA', 'CMFA', 'CMFB', 'CMGA', 'CMGB', 'CMHA', 'CMPA', 'CMSA', 'CMUA', 'CMXA', 'CNAA', 'CNCB', 'CNCD', 'CNCE', 'CNDA', 'CNHA', 'CNHC', 'CNRB', 'CNSB', 'CNTC', 'CNVA', 'CNYA', 'CNYB', 'CPAA', 'CPEA', 'CPMA', 'CPMB', 'CPNA', 'CPNB', 'CPSA', 'CPTA', 'CPWA', 'CRBC', 'CRBD', 'CRCA', 'CRDB', 'CREA', 'CREC', 'CRED', 'CREG', 'CREH', 'CRFA', 'CRFC', 'CRHA', 'CRKB', 'CRLB', 'CRLC', 'CRTC', 'CRTD', 'CRTE', 'CRTF', 'CRUA', 'CSPA', 'CSPB', 'CSSA', 'CSUA', 'CSUB', 'CSUD', 'CSUE', 'CSWB', 'CTBA', 'CTBB', 'CTBC', 'CTBD', 'CTCB', 'CTCC', 'CTDA', 'CTDB', 'CTEC', 'CTFA', 'CTGA', 'CTGE', 'CTGF', 'CTHG', 'CTNA', 'CTPA', 'CTPB', 'CTSA', 'CTTA', 'CTUA', 'CTUB', 'CTUC', 'CTUD', 'CTVA', 'CTWA', 'CTWB', 'CTXA', 'CTYA', 'CUEA', 'CUFA', 'CUHA', 'CUHB', 'CUJA', 'CUKB', 'CULB', 'CULC', 'CUNA', 'CUSB', 'CUVB', 'CUVC', 'CUVD', 'CUWA', 'CVBA', 'CVJA', 'CVKB', 'CVLA', 'CVMD', 'CVNA', 'CVPA', 'CVUA', 'CVUB', 'CVUC', 'CVZA', 'CWGD', 'CWLA', 'CWNA', 'CWPB', 'CWUB', 'CWUC', 'CWZA', 'CXMA', 'CXSA', 'CXSB', 'CXUA', 'CXXB', 'CYFB', 'CYGA', 'CYLA', 'CYMC', 'CYNB', 'CYPA', 'CYPB', 'CYRB', 'CYRC', 'CYVB', 'CYYA', 'CZAA', 'CZAC', 'CZCA', 'CZCC', 'CZDA', 'CZDB', 'CZDD', 'CZEA', 'CZGA', 'CZGB', 'CZHA', 'CZJA', 'CZPB', 'CZRA', 'CZSE', 'CZVA', 'CZVB', 'CZVC', 'CZVD', 'CZVE', 'CZVF', 'CZZA', 'CZZB', 'DADA', 'DAJB', 'DAXB', 'DAXC', 'DAYB', 'DAZA', 'DBBA', 'DBFB', 'DBGA', 'DBKA', 'DBPA', 'DBRA', 'DBSA', 'DCPC', 'DCYA', 'DDCA', 'DDCB', 'DDDA', 'DDEA', 'DDTA', 'DDVC', 'DDWA', 'DDYA', 'DECA', 'DEHA', 'DEJA', 'DEJB', 'DEMA', 'DESA', 'DETA', 'DETB', 'DEUA', 'DEUB', 'DEUC', 'DFGA', 'DFHA', 'DFTA', 'DFTB', 'DFTC', 'DFUA', 'DGCA', 'DHDA', 'DJHA', 'DJHB', 'DJJA', 'DJYA', 'DKAA', 'DKAB']
glv = ['81KW', '92KW', '110KW', '162KW', '121KW', '103KW', '66KW', '132KW', '85KW', '228KW', '240KW', '75KW', '245KW', '88KW', '195KW', '155KW', '250KW', '142KW', '100KW', '210KW', '200KW', '125KW', '171KW', '98KW', '183KW', '140KW', '130KW', '386KW', '60KW', '59KW', '220KW', '118KW', '120KW', '147KW', '280KW', '230KW', '169KW', '188KW', '44KW', '260KW', '83KW', '180KW', '37KW', '160KW', '105KW', '176KW', '320KW', '206KW', '309KW', '96KW', '128KW', '165KW', '63KW', '77KW', '45KW', '61KW', '294KW', '82KW', '331KW', '185KW', '213KW', '184KW', '57KW', '74KW', '265KW', '449KW', '368KW', '253KW', '101KW', '51KW', '135KW', '235KW', '412KW', '58KW', '55KW', '79KW', '25KW', '150KW', '246KW', '137KW', '191KW', '90KW', '397KW', '136KW', '445KW', '187KW', '154KW', '133KW', '38KW', '53KW', '190KW', '225KW', '215KW', '258KW', '353KW', '89KW', '202KW', '93KW', '382KW', '43KW', '52KW', '257KW', '64KW', '102KW', '141KW', '134KW', '40KW', '221KW', '115KW', '175KW', '273KW', '404KW', '232KW', '310KW', '283KW', '65KW', '119KW', '316KW', '270KW', '170KW', '114KW', '70KW', '199KW', '193KW', '48KW', '419KW', '106KW', '47KW', '29KW', '426KW']
items = []
client = MongoClient('192.168.10.170', 27017)
db = client.standard_label
collection = db.standard_label_unique
audiParts = CarsPartNumNew.select(CarsPartNumNew.brand_code, CarsPartNumNew.cid, CarsPartNumNew.extra_info,
                                  CarsPartNumNew.mid, CarsPartNumNew.model, CarsPartNumNew.pid, CarsPartNumNew.remark,
                                  CarsPartNumNew.sa_code)
for audiPart in audiParts:
    pid = audiPart.pid
    cid = audiPart.cid
    mid = audiPart.mid
    if pid != '' and ('dropped' not in audiPart.extra_info):
        stand_info = collection.find_one({'pid': pid, 'brandCode': 'audi'})
        stand_label = stand_info['standard_label'] if stand_info else ''
        if stand_label:
            # 配置代码
            sa_codes = []
            # 发动机缸数
            cylinder = []
            # 发动机代码
            vb = []
            # 发动机排量信息
            vb_desc = []
            transmission = []
            drive = []
            diff_mech = []
            # 燃油方式
            energy_type = []
            # 功率
            power = []
            # pSacodes = getSacode(audiPart.sa_code)
            part_sa_codes = audiPart.sa_code or '{}'
            part_sa_codes = ujson.loads(part_sa_codes)
            for key, value in part_sa_codes.items():
                if value:
                    sa_codes = sa_codes + value
            pModel = audiPart.model.replace('<br/>', '')
            pRemark = audiPart.remark

            pModelout = remove_tt(pModel)
            pRemarkout = remove_tt(pRemark)

            if pRemark:
                for key in s:
                    if key in pRemarkout:
                        cy = cleanCylinder(key)
                        cylinder.append(cy)
                for key in pl:
                    if key in pRemark:
                        vb_desc.append(key)

            if pModel:
                for key in bsx:
                    if key in pModelout:
                        tran = cleanTransmission(key)
                        transmission.append(tran)
                for key in qd:
                    if key in pModelout:
                        dr = cleanDrive(key)
                        drive.append(dr)

                for key in s:
                    if key in pModelout:
                        mcy = cleanCylinder(key)
                        cylinder.append(mcy)
                for key in pl:
                    if key in pModel:
                        vb_desc.append(key)
                for key in fdjdm:
                    if key in pModel:
                        vb.append(key)
                if 'PR:' in pModel or 'PR-' in pModel or 'pr:' in pModel or 'pr-' in pModel:
                    # 处理part_model中的PR
                    part_pr = re.sub('[\u4e00-\u9fa5]', '', pModel)
                    part_pr = part_pr.replace('PR:', '')
                    part_pr = part_pr.replace('PR-', '')
                    part_pr = part_pr.replace('+', ',')
                    part_pr = part_pr.replace('/', ',')
                    part_pr = part_pr.replace(':', ',')
                    part_pr = part_pr.replace('_', ',')
                    part_pr = part_pr.split(',')
                    for j in part_pr:
                        sa_codes.append(j)

            sa_codes = set(sa_codes)
            sa_codes = list(sa_codes)

            vb = set(vb)
            vb = list(vb)

            for i in sa_codes:
                if cid.startswith('U'):
                    contrast = CarsSaDesc.get_or_none(CarsSaDesc.cid == cid[1:], CarsSaDesc.sa == i, CarsSaDesc.lang == 'zh', CarsSaDesc.brand_code == 'audi')
                else:
                    contrast = CarsSaDesc.get_or_none(CarsSaDesc.cid == cid, CarsSaDesc.sa == i, CarsSaDesc.lang == 'zh', CarsSaDesc.brand_code == 'audi')
                if not contrast:
                    contrast = CarsSaDesc.get_or_none(CarsSaDesc.sa == i, CarsSaDesc.lang == 'zh',
                                                      CarsSaDesc.brand_code == audiPart.brand_code)
                if contrast and contrast.desc:
                    saDescout = remove_tt(contrast.desc)
                    # model_desc.append(contrast.desc)
                    if '发动机' in contrast.desc:
                        # 筛选出sa表desc中的排量信息
                        for key in pl:
                            if key in contrast.desc:
                                vb_desc.append(key)
                        for key in s:
                            if key in saDescout:
                                key = cleanCylinder(key)
                                cylinder.append(key)
                        for key in fuel:
                            if key in saDescout:
                                energy_type.append(key)
                        for key in glv:
                            if key in saDescout:
                                key = cleanPower(key)
                                power.append(key)

                    # 处理变速器配置
                    if ('变速箱' in contrast.desc or '变速器' in contrast.desc) and ('档' in contrast.desc or '无级' in contrast.desc):
                        for key in bsx:
                            if key in saDescout:
                                key = cleanTransmission(key)
                                transmission.append(key)

                    # 处理驱动配置
                    for key in qd:
                        if key in saDescout:
                            key = cleanDrive(key)
                            drive.append(key)

                    # 处理差速器配置
                    if '差速' in contrast.desc or '减速' in contrast.desc:
                        diff_mech.append(contrast.desc)

            for i in vb:
                if cid.isdigit():
                    vb_AF = Vb.get_or_none(Vb.aa == str(int(cid)), Vb.ab.contains(i), Vb.brand == 'audi')
                elif cid.startswith('U'):
                    vb_AF = Vb.get_or_none(Vb.aa == cid[1:], Vb.ab.contains(i), Vb.brand == 'audi')
                else:
                    vb_AF = Vb.get_or_none(Vb.aa == cid, Vb.ab.contains(i), Vb.brand == 'audi')
                if vb_AF:
                    if vb_AF.af:
                        vb_desc.append(str(int(vb_AF.af)/100))
                    if vb_AF.ai:
                        cylinder.append(vb_AF.ai)
                    if vb_AF.ag:
                        power.append(vb_AF.ag)

            # 处理part时间
            date, colorDate, year = audi_do_filter_extra_info(audiPart.extra_info)
            dateLeft, dateRight = mergeDate(date)
            colordateLeft, colordateRight = mergeDate(colorDate)
            yearLeft, yearRight = mergeDate(year)

            leftList = []
            if dateLeft:
                leftList.append(dateLeft)
            if colordateLeft:
                leftList.append(colordateLeft)
            if yearLeft:
                leftList.append(yearLeft)
            rightList = []
            if dateRight:
                rightList.append(dateRight)
            if colordateRight:
                rightList.append(colordateRight)
            if yearRight:
                rightList.append(yearRight)
            mdateLeft = max(leftList) if leftList else ''
            mdateRight = min(rightList) if rightList else ''
            merge_date = mdateLeft + ('-' if mdateLeft or mdateRight else '') + mdateRight

            vb_desc = set(vb_desc)
            vb_desc = list(vb_desc)
            vb_desc = ','.join(vb_desc)

            cylinder = set(cylinder)
            cylinder = list(cylinder)
            cylinder = ','.join(cylinder)

            transmission = set(transmission)
            transmission = list(transmission)
            transmission = ','.join(transmission)

            drive = set(drive)
            drive = list(drive)
            drive = ','.join(drive)

            diff_mech = set(diff_mech)
            diff_mech = list(diff_mech)
            diff_mech = ','.join(diff_mech)

            energy_type = set(energy_type)
            energy_type = list(energy_type)
            energy_type = ','.join(energy_type)

            power = set(power)
            power = list(power)
            power = ','.join(power)

            vb = ','.join(vb)

            ssa_codes = []
            # 发动机缸数
            scylinder = []
            # 发动机代码
            svb = []
            # 发动机排量信息
            svb_desc = []
            stransmission = []
            sdrive = []
            sdiff_mech = []
            # 燃油方式
            senergy_type = []
            spower = []
            merge_sdate = ''
            audiStructure = CarsStructureCollectionNew.get_or_none(CarsStructureCollectionNew.cid == audiPart.cid, CarsStructureCollectionNew.mid == audiPart.mid)

            # sSacodes = getSacode(audiStructure.sa_code)
            if audiStructure:
                structure_sa_codes = audiStructure.sa_code or '{}'
                structure_sa_codes = ujson.loads(structure_sa_codes)
                for key, value in structure_sa_codes.items():
                    if value:
                        ssa_codes = ssa_codes + value
                sModel = audiStructure.model.replace('<br/>', '')
                sDescription = audiStructure.description

                sModelout = remove_tt(sModel)
                sDescriptionout = remove_tt(sDescription)

                if sDescription:
                    for key in s:
                        if key in sDescriptionout:
                            key = cleanCylinder(key)
                            scylinder.append(key)
                    for key in pl:
                        if key in sDescription:
                            svb_desc.append(key)

                if sModel:
                    for key in bsx:
                        if key in sModelout:
                            key = cleanTransmission(key)
                            stransmission.append(key)
                    for key in qd:
                        if key in sModelout:
                            key = cleanDrive(key)
                            sdrive.append(key)

                    for key in s:
                        if key in sModelout:
                            key = cleanCylinder(key)
                            scylinder.append(key)
                    for key in pl:
                        if key in sModel:
                            svb_desc.append(key)
                    for key in fdjdm:
                        if key in sModel:
                            svb.append(key)
                    if 'PR:' in sModel or 'PR-' in sModel or 'pr:' in sModel or 'pr-' in sModel:
                        # 处理part_model中的PR
                        s_pr = re.sub('[\u4e00-\u9fa5]', '', sModel)
                        s_pr = s_pr.replace('PR:', '')
                        s_pr = s_pr.replace('PR-', '')
                        s_pr = s_pr.replace('+', ',')
                        s_pr = s_pr.replace('/', ',')
                        s_pr = s_pr.replace(':', ',')
                        s_pr = s_pr.replace('_', ',')
                        s_pr = s_pr.split(',')
                        for j in s_pr:
                            ssa_codes.append(j)

                for i in ssa_codes:
                    if cid.startswith('U'):
                        contrast = CarsSaDesc.get_or_none(CarsSaDesc.cid == cid[1:], CarsSaDesc.sa == i,
                                                          CarsSaDesc.lang == 'zh', CarsSaDesc.brand_code == 'audi')
                    else:
                        contrast = CarsSaDesc.get_or_none(CarsSaDesc.cid == cid, CarsSaDesc.sa == i,
                                                          CarsSaDesc.lang == 'zh', CarsSaDesc.brand_code == 'audi')
                    if not contrast:
                        contrast = CarsSaDesc.get_or_none(CarsSaDesc.sa == i, CarsSaDesc.lang == 'zh', CarsSaDesc.brand_code == audiPart.brand_code)
                    if contrast and contrast.desc:
                        ssaDescout = remove_tt(contrast.desc)
                        # model_desc.append(contrast.desc)
                        if '发动机' in contrast.desc:
                            # 筛选出sa表desc中的排量信息
                            for key in pl:
                                if key in contrast.desc:
                                    svb_desc.append(key)
                            for key in s:
                                if key in ssaDescout:
                                    key = cleanCylinder(key)
                                    scylinder.append(key)
                            for key in fuel:
                                if key in ssaDescout:
                                    senergy_type.append(key)
                            for key in glv:
                                if key in ssaDescout:
                                    key = cleanPower(key)
                                    spower.append(key)

                        # 处理变速器配置
                        if ('变速箱' in contrast.desc or '变速器' in contrast.desc) and ('档' in contrast.desc or '无级' in contrast.desc):
                            for key in bsx:
                                if key in ssaDescout:
                                    key = cleanTransmission(key)
                                    stransmission.append(key)

                        # 处理驱动配置
                        for key in qd:
                            if key in ssaDescout:
                                key = cleanDrive(key)
                                sdrive.append(key)

                        # 处理差速器配置
                        if '差速' in contrast.desc or '减速' in contrast.desc:
                            sdiff_mech.append(contrast.desc)

                for i in svb:
                    if cid.isdigit():
                        vb_AF = Vb.get_or_none(Vb.aa == str(int(cid)), Vb.ab.contains(i), Vb.brand == 'audi')
                    elif cid.startswith('U'):
                        vb_AF = Vb.get_or_none(Vb.aa == cid[1:], Vb.ab.contains(i), Vb.brand == 'audi')
                    else:
                        vb_AF = Vb.get_or_none(Vb.aa == cid, Vb.ab.contains(i), Vb.brand == 'audi')
                    if vb_AF:
                        if vb_AF.af:
                            svb_desc.append(str(int(vb_AF.af)/100))
                        if vb_AF.ai:
                            scylinder.append(vb_AF.ai)
                        if vb_AF.ag:
                            spower.append(vb_AF.ag)

                sdate, scolordate, syear = audi_do_filter_extra_info(audiStructure.extra_info)
                sdateLeft, sdateRight = mergeDate(sdate)
                scolordateLeft, scolordateRight = mergeDate(scolordate)
                syearLeft, syearRight = mergeDate(syear)
                # sleftList = [sdateLeft, scolordateLeft, syearLeft]
                # srightList = [sdateRight, scolordateRight, syearRight]
                sleftList = []
                if sdateLeft:
                    sleftList.append(sdateLeft)
                if scolordateLeft:
                    sleftList.append(scolordateLeft)
                if syearLeft:
                    sleftList.append(syearLeft)
                srightList = []
                if sdateRight:
                    srightList.append(sdateRight)
                if scolordateRight:
                    srightList.append(scolordateRight)
                if syearRight:
                    srightList.append(syearRight)
                msdateLeft = max(sleftList) if sleftList else ''
                msdateRight = min(srightList) if srightList else ''
                merge_sdate = msdateLeft + ('-' if msdateLeft or msdateRight else '') + msdateRight

            svb_desc = set(svb_desc)
            svb_desc = list(svb_desc)
            svb_desc = ','.join(svb_desc)

            scylinder = set(scylinder)
            scylinder = list(scylinder)
            scylinder = ','.join(scylinder)

            stransmission = set(stransmission)
            stransmission = list(stransmission)
            stransmission = ','.join(stransmission)

            sdrive = set(sdrive)
            sdrive = list(sdrive)
            sdrive = ','.join(sdrive)

            sdiff_mech = set(sdiff_mech)
            sdiff_mech = list(sdiff_mech)
            sdiff_mech = ','.join(sdiff_mech)

            senergy_type = set(senergy_type)
            senergy_type = list(senergy_type)
            senergy_type = ','.join(senergy_type)

            spower = set(spower)
            spower = list(spower)
            spower = ','.join(spower)

            svb = ','.join(svb)

            unit = {'pid': audiPart.pid, 'cid':audiPart.cid, 'mid':audiPart.mid, 'brand_code': audiPart.brand_code, 'standard_label': stand_label, 'engine_code': vb,
                    'cylinder': cylinder, 'transmission': transmission, 'drive': drive, 'diff_mech': diff_mech, 'displacement': vb_desc, 'pid_date': merge_date, 'energy_type': energy_type, 'power': power,
                    'group_engine_code': svb, 'group_cylinder': scylinder, 'group_transmission': stransmission, 'group_drive': sdrive, 'group_diff_mech':sdiff_mech, 'group_displacement': svb_desc, 'group_date': merge_sdate, 'group_energy_type': senergy_type, 'group_power': spower}
            print(unit)
            items.append(unit)

df = pd.DataFrame(items)
df['pid'] = df['pid'].astype('str')
df.to_csv('./export/audi_parts.csv', mode='a', index=False)